﻿Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary

<Serializable()> Public Class OpenPitSource
    Inherits BaseSource
    Implements ICloneable

    Private m_Relhgt As Double = 0.0
    Private m_Xinit As Double = 500
    Private m_Yinit As Double = 1000
    Private m_Angle As Double = 0
    Private m_Pitvol As Double = 500000
    Private m_ArrayTop(2) As Point
    Private m_PolluteUnit As String = "g/s•m^2"  '污染物排放速率单位

    ''' <summary>
    ''' 敞口源的平均高度，m
    ''' </summary>
    ''' <remarks></remarks>
    Public Property Relhgt() As Double
        Get
            Return Me.m_Relhgt
        End Get
        Set(ByVal value As Double)
            Me.m_Relhgt = value
        End Set
    End Property
    ''' <summary>
    ''' 敞口源X边的长度，m
    ''' </summary>
    ''' <remarks></remarks>
    Public Property Xinit() As Double
        Get
            Return Me.m_Xinit
        End Get
        Set(ByVal value As Double)
            Me.m_Xinit = value
        End Set
    End Property
    ''' <summary>
    ''' 敞口源Y边的长度，m
    ''' </summary>
    ''' <remarks></remarks>
    Public Property Yinit() As Double
        Get
            Return Me.m_Yinit
        End Get
        Set(ByVal value As Double)
            Me.m_Yinit = value
        End Set
    End Property
    ''' <summary>
    ''' 敞口源的方向角
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Angle() As Double
        Get
            Return Me.m_Angle
        End Get
        Set(ByVal value As Double)
            Me.m_Angle = value
        End Set
    End Property
    ''' <summary>
    ''' 敞口源的烟羽的体积，m3
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Pitvol() As Double
        Get
            Return Me.m_Pitvol
        End Get
        Set(ByVal value As Double)
            Me.m_Pitvol = value
        End Set
    End Property
    ''' <summary>
    ''' 矩形面源的其它3个顶点的坐标，不含Z坐标
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property ArrayTop() As Point()
        Get
            Return m_ArrayTop
        End Get
        Set(ByVal value As Point())
            m_ArrayTop = value
        End Set
    End Property
    ''' <summary>
    ''' 污染物的单位
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property PolluteUnit() As String
        Get
            Return m_PolluteUnit
        End Get
        Set(ByVal value As String)
            m_PolluteUnit = value
        End Set
    End Property
    ''' <summary>
    ''' 根据输入的角度等信息转换为顶点信息
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub AngleToTop()
        '求得第2个顶点的坐标
        m_ArrayTop(0).X = Me.Location.Xs + Me.m_Yinit * Math.Cos((90 - Me.m_Angle) / 180 * Math.PI)
        m_ArrayTop(0).Y = Me.Location.Ys + Me.m_Yinit * Math.Sin((90 - Me.m_Angle) / 180 * Math.PI)
        '求得第3个顶点的坐标
        m_ArrayTop(1).X = m_ArrayTop(0).X + Me.m_Yinit * Math.Cos((0 - Me.m_Angle) / 180 * Math.PI)
        m_ArrayTop(1).Y = m_ArrayTop(0).Y + Me.m_Yinit * Math.Sin((0 - Me.m_Angle) / 180 * Math.PI)
        '求得第4个顶点的坐标
        m_ArrayTop(2).X = Me.Location.Xs + Me.m_Yinit * Math.Cos((0 - Me.m_Angle) / 180 * Math.PI)
        m_ArrayTop(2).Y = Me.Location.Ys + Me.m_Yinit * Math.Sin((0 - Me.m_Angle) / 180 * Math.PI)

    End Sub
    ''' <summary>
    ''' 根据污染源污染物的名称返回相应的排放速率
    ''' </summary>
    ''' <param name="name">污染物的名称</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetRate(ByVal name As String) As Decimal
        If Me.m_PollutionPara IsNot Nothing AndAlso Me.m_PollutionPara.Length > 0 Then
            For i As Integer = 0 To Me.m_PollutionPara.Length - 1
                If Me.m_PollutionPara(i).Name = name Then
                    If Me.m_PolluteUnit = "g/s•m^2" Then
                        Return Me.m_PollutionPara(i).Ptemis  '返回污染物排放速率
                    ElseIf Me.m_PolluteUnit = "g/s" Then
                        Return Me.m_PollutionPara(i).Ptemis / (Me.m_Xinit * Me.m_Yinit) '返回污染物排放速率
                    ElseIf Me.m_PolluteUnit = "kg/h" Then
                        Return Me.m_PollutionPara(i).Ptemis / (Me.m_Xinit * Me.m_Yinit) * 1000 / 3600 '返回污染物排放速率
                    Else
                        MessageBox.Show("敞口源的排放速率单位出错!")
                    End If
                End If
            Next
        End If
    End Function
    ''' <summary>
    ''' 根据污染源污染物的名称返回相应的污染物ID
    ''' </summary>
    ''' <param name="name">污染物的名称</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetPolluteID(ByVal name As String) As Integer
        If Me.m_PollutionPara IsNot Nothing AndAlso Me.m_PollutionPara.Length > 0 Then
            For i As Integer = 0 To Me.m_PollutionPara.Length - 1
                If Me.m_PollutionPara(i).Name = name Then
                    Return i
                    Exit Function
                End If
            Next
        End If
    End Function
    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj As New OpenPitSource
        obj.m_Location = Me.m_Location.Clone   '污染源的位置等参数
        ReDim obj.PollutionPara(Me.m_PollutionPara.Length - 1) '污染物名称和排放速率。因为同一排放源，其污染物不一样，则排放速率不一样。
        For i As Integer = 0 To Me.m_PollutionPara.Length - 1
            obj.PollutionPara(i) = Me.m_PollutionPara(i).Clone
        Next
        obj.m_SourceName = Me.m_SourceName  '污染源的名称
        obj.m_Urbansrc = Me.m_Urbansrc.Clone '考虑城市影响
        obj.m_EmisFact = Me.m_EmisFact.Clone  '排放速率变化
        obj.m_NowPolluteID = Me.m_NowPolluteID  '表示当前选择的污染物
        obj.m_NO2Ratio = Me.m_NO2Ratio.Clone  '指定污染源NO2的排放比例


        obj.m_Relhgt = Me.m_Relhgt
        obj.m_Xinit = Me.m_Xinit
        obj.m_Yinit = Me.m_Yinit
        obj.m_Angle = Me.m_Angle
        obj.m_Pitvol = Me.m_Pitvol
        ReDim obj.m_ArrayTop(Me.m_ArrayTop.Length - 1)
        For i As Integer = 0 To Me.m_ArrayTop.Length - 1
            obj.m_ArrayTop(i) = Me.m_ArrayTop(i)
        Next
        obj.m_PolluteUnit = Me.m_PolluteUnit
        obj.IsSourceHour = Me.IsSourceHour
        Return obj
    End Function
    <OnDeserializing()> _
Friend Sub OnDeserializingMethod(ByVal context As StreamingContext)

    End Sub

    <OnDeserialized()> _
    Friend Sub OnDeserializedMethod(ByVal context As StreamingContext)
        If Me.m_PolluteUnit Is Nothing Then
            Me.m_PolluteUnit = "g/s•m^2"
        End If
    End Sub
End Class
